package cz.cvut.vrtisja2.muchktom.view.spinner;

import android.app.Dialog;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Spinner;
import cz.cvut.vrtisja2.muchktom.view.newItem.CustomDialogAct;
import cz.cvut.vrtisja2.muchktom.view.newItem.NewItemActivity;

public class JvSpinnerListener implements OnItemSelectedListener {
	
	private NewItemActivity controller; 
	private Spinner spinner;
	ISpinnerDataStrategy strategy;

	// ====================Static variables===================

	// ====================Instance variables==================

	// ====================Constructors========================
	public JvSpinnerListener (NewItemActivity act, Spinner spinner, ISpinnerDataStrategy strategy){
		this.controller=act;
		this.spinner=spinner;
		this.strategy=strategy;
		
	}
	

	// ====================Instance Methods====================

	@Override
	public void onItemSelected(AdapterView<?> arg0, View view, int pos,
			long id) {
		//Pokud jsme klikli na posledni pozici je vybrano talcisko new
		Log.d("JV", "pozice: "+pos+ "v adapt: "+spinner.getAdapter().getCount());
		
		if(pos+1==spinner.getAdapter().getCount()){
			Dialog d = CustomDialogAct.getCustomDialog(controller,spinner,strategy,pos);
			d.show();
		}
		
	}

	@Override
	public void onNothingSelected(AdapterView<?> arg0) {
		// TODO Auto-generated method stub
	}

	// ====================Getters & Setters===================
	
	

	// ====================Inner classes=======================

}
